Skip to content

fix(sandbox): scope quota cleanup to the sandbox owner - #1153

Merged
ak684 merged 3 commits into
mainfrom
alona/sandbox-owner-quota
Nov 3, 2026
Merged

ak684 merged 3 commits into
mainfrom
alona/sandbox-owner-quota

Conversation

@ak684

@ak684 ak684 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

AGENT:


Why

An ADMIN-context resume can apply one user's sandbox quota to every running remote sandbox because ADMIN can read every owner's database rows. Resuming one paused sandbox can therefore pause unrelated users' work in OHE or SaaS deployments using this backend.

Summary

  • Scope quota cleanup to the target sandbox's stored owner while retaining caller authorization.
  • Exclude the resumed sandbox from cleanup and reject ownerless quota operations before listing or pausing runtimes.
  • Cover multiple owners, normal starts, active/unauthorized resumes, and a target becoming running during cleanup with real PostgreSQL regression tests.

Issue Number

Fixes OSS-15057.

How to Test

Run uv run pytest -q tests/unit/app_server/test_remote_sandbox_quota_ownership.py tests/unit/app_server/test_remote_sandbox_service.py tests/unit/app_server/test_sandbox_resume_git_config.py tests/unit/integrations/slack/test_slack_view.py with the repository PostgreSQL fixture: 166 passed. Eight regression cases fail against the original service. Pre-commit checks, including mypy, pass.

Live OHE/Replicated test: executed the exact candidate service in an isolated app-pod process against real PostgreSQL and runtime pods. An ADMIN resume paused only the owner's oldest sandbox; another owner's sandbox and background process survived. Trial resources were cleaned and app configuration preserved. Packaged rollout and browser/integration end-to-end testing remain.

Video/Screenshots

Backend-only change; assertions checked the runtime mutation sequence and the unrelated process's PID/start time.

Type

  • Bug fix

Notes

No migrations or configuration changes. Ownerless paused sandboxes now return 409. The owner's oldest-running policy is unchanged: idle-only selection and concurrent quota serialization remain follow-ups.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-278ce84

@github-actions github-actions Bot added the type: fix A bug fix label Nov 3, 2026
@ak684
ak684 requested a review from all-hands-bot November 3, 2026 17:47
@all-hands-bot

all-hands-bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review posted for 278ce84c73ba

Verdict: ✅ APPROVED. See the review.

This is an automated status.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/sandbox
  remote_sandbox_service.py 1066
Project Total  

This report was generated by python-coverage-comment-action

@all-hands-bot all-hands-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was posted by an AI agent (OpenHands).

The fix is correct, and I found no material issues.

What I checked

  • Root cause. secure_select returns every row for ADMIN. Before this change, quota cleanup under an ADMIN context, such as the Slack resume path in integrations/slack/slack_view.py, counted and paused the oldest running remote sandboxes of all users. _get_user_running_sandboxes now always filters on created_by_user_id == owner_user_id. resume_sandbox passes the stored owner of the target sandbox. The start path still uses the caller's user id. A non-ADMIN caller is still limited by secure_select, so an explicit owner_user_id cannot reach rows the caller could not already see. test_explicit_quota_owner_does_not_bypass_caller_access covers this.
  • Ownerless handling. An ADMIN start or cleanup without an owner now fails before /list or /pause. Before, it paused sandboxes across all users. The 409 on resume of an ownerless paused sandbox is a deliberate trade-off, and the PR notes say so.
  • exclude_id=sandbox_id on resume. This matches ManagedSandboxService.resume_sandbox. It stops a target that becomes running during cleanup from being counted against the limit, or paused by its own resume. The concurrent_resume case covers this.
  • Other entry points. Docker, E2B and K8s already require a user id before they call pause_old_sandboxes, so this change brings the remote backend in line with them.

Validation

  • In the workspace with the repository PostgreSQL fixture, I ran the four test files from the PR at the head commit: 166 passed.
  • I ran the new test_remote_sandbox_quota_ownership.py against the main service: 9 cases fail and 5 pass. Some of the failures come from the new owner_user_id keyword. The multi-owner, ownerless and ADMIN start cases fail on behavior.
  • All GitHub Actions checks on 358ca1b8c85b pass, including the four Python test shards, Lint python and Budget regressions.

✅ APPROVED

LLM profile: all-hands-bot-reviewer_claude-opus-5-5 · Model: openhands/claude-opus-5-5

@ak684
ak684 marked this pull request as ready for review November 3, 2026 18:05
@ak684
ak684 enabled auto-merge (squash) November 3, 2026 18:10
@ak684
ak684 merged commit a163206 into main Nov 3, 2026
20 checks passed
@ak684
ak684 deleted the alona/sandbox-owner-quota branch November 3, 2026 19:19
@openhands-release-bot openhands-release-bot Bot added the released: 1.85.0 Shipped in 1.85.0 label Nov 3, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.85.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.85.0 Shipped in 1.85.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants